package cn.iocoder.yudao.module.system.convert.tenant;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.collection.MapUtils;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.system.controller.admin.tenantapprovelist.vo.TenantApproveListRespVO;
import cn.iocoder.yudao.module.system.controller.admin.tenantrechargelist.vo.TenantRechargeListRespVO;
import cn.iocoder.yudao.module.system.dal.dataobject.tenant.TenantDO;
import cn.iocoder.yudao.module.system.dal.dataobject.tenantapprovelist.TenantApproveListDO;
import cn.iocoder.yudao.module.system.dal.dataobject.tenantrechargelist.TenantRechargeListDO;
import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * 租户 Convert
 *
 * @author 芋道源码
 */
@Mapper
public interface TenantApproveListConvert {

    TenantApproveListConvert INSTANCE = Mappers.getMapper(TenantApproveListConvert.class);

    default TenantApproveListRespVO convert0(TenantApproveListDO data, Map<Long, TenantDO> tenantMap, Map<Long, AdminUserDO> userMap) {
        TenantApproveListRespVO respVO = BeanUtils.toBean(data, TenantApproveListRespVO.class);
        MapUtils.findAndThen(userMap, data.getOperator(), (user) -> respVO.setOperatorName(user.getNickname()));
        MapUtils.findAndThen(tenantMap, data.getTenantId(), (user) -> respVO.setTenantName(user.getName()));
        return respVO;
    }

    default PageResult<TenantApproveListRespVO> convert(PageResult<TenantApproveListDO> result1, Map<Long, TenantDO> tenantMap,  Map<Long, AdminUserDO> userMap) {
        List<TenantApproveListRespVO> orderRespVOS = result1.getList().stream().map(data -> convert0(data, tenantMap, userMap)).collect(Collectors.toList());
        PageResult<TenantApproveListRespVO> result2 = new PageResult<>();
        result2.setList(orderRespVOS);
        result2.setTotal(result1.getTotal());
        return result2;
    }

}
